package com.unismc.uview.config;

import java.nio.charset.StandardCharsets;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestConfiguration {

	@Bean
	public RestTemplate restTemplate() {
		//设置apache httpclient为默认的工具，以支持gzip,maven中已手动增加httpclient依赖
		RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
		//设置中文编码支持，不设置时使用默认编码，会有乱码
		restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
		return restTemplate;
	}

}
